package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"os"
)

var (
	gitbranch string
	githash string
	buildstamp string
	goversion string
)

func main() {
	args := os.Args
	if len(args) == 2 && (args[1] == "--version" || args[1] == "-v") {
		fmt.Printf("Git Branch: %s\n", gitbranch)
		fmt.Printf("Git Commit Hash: %s\n", githash)
		fmt.Printf("UTC Build Time : %s\n", buildstamp)
		fmt.Printf("go version : %s\n", goversion)
		return
	}

	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{"message":"pong"})

	})
	_ = r.Run()
}
// go build -ldflags "-X 'main.goversion=$(go version)' -X 'main.buildstamp=`date`' -X 'main.githash=`date`' -X main.githash=`git describe --long --dirty --abbrev=14` -X main.gitbranch=`git symbolic-ref --short -q HEAD`"  -o build-version main.go